package org.millioncall.yueyoga.admin.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.millioncall.openplatform.common.PaginateParams;
import org.millioncall.openplatform.common.PaginatedList;
import org.millioncall.openplatform.common.StartLimitPairImpl;
import org.millioncall.openplatform.dao.PreparedQuery;
import org.millioncall.yueyoga.admin.dao.BaseDao;
import org.millioncall.yueyoga.admin.dao.RechargeDAO;
import org.millioncall.yueyoga.admin.model.Recharge;

public class RechargeDAOImpl extends BaseDao implements RechargeDAO {

	@Override
	public void recharge(Recharge recharge) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("memberId", recharge.getMember().getMemberid());
		map.put("recharge", recharge.getRecharge());
		map.put("money", recharge.getMoney());
		map.put("remarks", recharge.getRemarks());
		map.put("userId", 1);
		this.getPagableSqlSessionTemplate().insert("recharge", map);
	}

	@Override
	public PaginatedList<Recharge> findInPage(Integer start, Integer limit, Map<String, Object> map) {
		PreparedQuery<Recharge> pq = this.getPagableSqlSessionTemplate()
				.findAll("findAllRecharge");
		PaginatedList<Recharge> pl = pq.list(new PaginateParams(
				new StartLimitPairImpl(start, limit)));
		return pl;
	}

	@Override
	public PaginatedList<Recharge> findInPage(Integer start, Integer limit,
			String[] paramNames, String[] paramValues) {
		PreparedQuery<Recharge> pq = this.getPagableSqlSessionTemplate()
				.findAll("findAllRecharge");
		PaginatedList<Recharge> pl = pq.list(new PaginateParams(
				new StartLimitPairImpl(start, limit)));
		return pl;
	}

	@Override
	public PaginatedList<Recharge> findByMemberId(Integer start, Integer limit,
			Integer memberId) {
		PreparedQuery<Recharge> pq = this.getPagableSqlSessionTemplate()
				.findAll("findRechargeByMemberId", memberId);
		PaginatedList<Recharge> pl = pq.list(new PaginateParams(
				new StartLimitPairImpl(start, limit)));
		return pl;
	}
	
	@Override
	public PaginatedList<Recharge> findTiquByMemberId(Integer start, Integer limit,
			Integer memberId) {
		PreparedQuery<Recharge> pq = this.getPagableSqlSessionTemplate()
				.findAll("findTiquRechargeByMemberId", memberId);
		PaginatedList<Recharge> pl = pq.list(new PaginateParams(
				new StartLimitPairImpl(start, limit)));
		return pl;
	}

	@Override
	public int insert(Recharge recharge) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("memberId", recharge.getMember().getMemberid());
		map.put("recharge", recharge.getRecharge());
		map.put("money", recharge.getMoney());
		map.put("type", recharge.getType());
		map.put("remarks", recharge.getRemarks());
		map.put("userId", recharge.getUser().getId());
		map.put("createTime", recharge.getCreateTime());
		map.put("logType", recharge.getLogType());
		map.put("organizationId", recharge.getOrganizationId());
		return this.getPagableSqlSessionTemplate()
				.insert("insertRecharge", map);
	}

	@Override
	public PaginatedList<Recharge> findRechargeByMap(int start, int limit,
			Map<String, Object> map) {
		PreparedQuery<Recharge> pq = this.getPagableSqlSessionTemplate()
				.findAll("findRechargeByMap", map);
		PaginatedList<Recharge> pl = pq.list(new PaginateParams(
				new StartLimitPairImpl(start, limit)));
		return pl;
	}

}
